package com.college_career_system.controller;


import com.alibaba.fastjson.JSONObject;
import com.college_career_system.pojo.dto.EnterpriseDTO;
import com.college_career_system.service.EnterpriseService;
import com.college_career_system.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Empty
 * @since 2022-12-04
 */
@RestController
@RequestMapping("/enterprise")
@CrossOrigin(origins = Constant.URL, allowCredentials = "true", maxAge = 3600)
public class EnterpriseController {

    @Autowired
    private EnterpriseService enterpriseService;

    /**
     * 企业注册，除了enterpriseId，其余都要输入，结果会返回企业账号
     * @param enterpriseDTO
     * @return
     */
    @PostMapping("/enterpriseRegister")
    JSONObject EnterpriseRegister(EnterpriseDTO enterpriseDTO) {
        return enterpriseService.EnterpriseRegister(enterpriseDTO);
    }

    /**
     * 企业登入，输入账号密码
     * @param account
     * @param psw
     * @return
     */
    @PostMapping("/enterpriseLogin")
    public JSONObject EnterpriseLogin(String account, String psw) {
        return enterpriseService.EnterpriseLogin(account, psw);
    }

    /**
     * 企业查询收到的简历，flag=0表示未录取，flag=1表示录取，flag=2表示拒绝录取
     * @param request
     * @param flag
     * @return
     */
    @PostMapping("/selectReceivedRecruit")
    public JSONObject selectReceivedRecruit(HttpServletRequest request, int flag) {
        return enterpriseService.selectReceivedRecruit(request, flag);
    }

    /**
     * 企业同意/拒绝某人简历，根据传入的hid进行更新，flag如上
     * @param hid   投递后产生的一条数据的主键
     * @param flag
     * @param uid   通过传入的学生学号判断是否该学生已经就业
     * @return
     */
    @PostMapping("/updateState")
    public JSONObject updateState(int hid, int flag, String uid) {
        return enterpriseService.updateState(hid, flag, uid);
    }

    /**
     * 更新密码 传入新的密码
     * @param request
     * @param pwd
     * @return
     */
    @PostMapping("/updatePassWordById")
    @ResponseBody
    public  String updatePassWordById(HttpServletRequest request, String pwd) {
        return enterpriseService.updatePassWordById(request, pwd).toString();
    }

}

